<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2018/7/30
 * Time: 14:45
 */

namespace wechat\core;
use wechat\Wx;

/**
 * 用户管理类
 * Class User
 * @package wechat\core
 */
class User extends Wx
{

    /**
     * 创建标签方法
     * 参照手册 用户管理->用户标签
     */
  public function createTag($post){
//    print_r($post);
      $token = $this->getAccessToken();
//      print_r($token);
      $url = 'https://api.weixin.qq.com/cgi-bin/tags/create?access_token='.$token;
      $data = $this->curl($url,$post);
      $data = json_decode($data,true);
//      print_r($data);
      if(isset($data['tag'])){
          return true;
      }else{
          return false;
      }
  }

  public function getTag(){
      $url = 'https://api.weixin.qq.com/cgi-bin/tags/get?access_token='.$this->getAccessToken();
//      echo $url;
      $data = $this->curl($url);
      $data = json_decode($data,true);
      print_r($data);
      if(isset($data['tags'])){
          return true;
      }else{
          return false;
      }
  }

    /**
     * 编辑标签方法
     */
  public function updataTag($post){
      $url = 'https://api.weixin.qq.com/cgi-bin/tags/update?access_token='.$this->getAccessToken();
      $data = $this->curl($url,$post);
      $data = json_decode($data,true);
      print_r($data);
      if($data['errcode'] ==0 ){
          return true;
      }else{
          return false;
      }
  }

    /**
     * 删除标签方法
     */
  public function deleteTag($post){
      $url = 'https://api.weixin.qq.com/cgi-bin/tags/delete?access_token='.$this->getAccessToken();
      $data = $this->curl($url,$post);
      $data = json_decode($data,true);
      if($data['errcode'] ==0){
          return true;
      }else{
          return false;
      }
  }

    /**
     * 设置用户备注名
     * @param $post
     * @return bool
     */
  public function setMark($post){
      $url = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token='.$this->getAccessToken();
      $data = $this->curl($url,$post);
      $data = json_decode($data,true);
//      print_r($data);
      if($data['errcode'] ==0){
          return true;
      }else{
          return false;
      }
  }

    /**
     * 获得单一用户基本信息
     */
  public function getUserInfo($openid,$lang = 'zh_CN'){
      $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$this->getAccessToken().'&openid='.$openid.'&lang='.$lang;
      $data = $this->curl($url);
      $data = json_decode($data,true);
//      print_r($data);
      if($data['errcode']==0){
          return $data;
      }else{
          return false;
      }
  }

    /**
     * 批量获取用户数据 最多100条
     * @param $post
     * @return bool|mixed|string
     */
  public function userInfoList($post){
      $url = 'https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token='.$this->getAccessToken();
      $data = $this->curl($url,$post);
      $data = json_decode($data,true);
      if($data['errcode'] ==0){
          return $data;
      }else{
          return true;
      }
  }

  /**
   * 获得用户列表方法
   */
    public function getUserList(){
        $url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token='.$this->getAccessToken();
        $data = $this->curl($url);
        $data = json_decode($data,true);
        if($data['errcode'] == 0){
            return $data;
        }else{
            return false;
        }



    }









}